#include <QVBoxLayout>
#include "Designer.h"
#include "DesignerContainer.h"
#include "StatusBar.h"

namespace Plugins
{

DesignerContainer::DesignerContainer(Designer *edit, QWidget *parent, Project * prj):
    QWidget(parent),
    _edit(edit)
{
    setLayout(new QVBoxLayout());
    layout()->setContentsMargins(0, 0, 0, 0);
    _bar = new StatusBar(this);
    edit->setStatusBar(_bar);
    edit->setProject(prj);
    layout()->addWidget(_bar);
    layout()->addWidget(edit->widget());

    connect(_edit->widget(), SIGNAL(fileChanged(bool)), SIGNAL(modifyChanged(bool)));
    connect(_edit->widget(), SIGNAL(copyAvailable(bool)), SIGNAL(copyAvailable(bool)));
    connect(_edit->widget(), SIGNAL(undoAvailable(bool)), SIGNAL(undoAvailable(bool)));
    connect(_edit->widget(), SIGNAL(redoAvailable(bool)), SIGNAL(redoAvailable(bool)));
    connect(_edit->widget(), SIGNAL(copyAvailable(bool)), SIGNAL(copyAvailable(bool)));

    connect(_bar, SIGNAL(closeRequest()), SIGNAL(closeEditor()));
    connect(_edit, SIGNAL(fileChanged(bool)), _bar, SLOT(setModify(bool)));
}

QWidget * DesignerContainer::widget()
{
    return this;
}

bool DesignerContainer::save()
{
    return _edit->saveFile();
}

bool DesignerContainer::load(const QString & path)
{
    return _edit->loadFile(path);
}

void DesignerContainer::setStatusBarVisible(bool show)
{
    if (_bar) _bar->setVisible(show);
}

QsciLexer * DesignerContainer::getLexer(){ return NULL; }
void DesignerContainer::setLexerByName(const QString& /*lexName*/){}
void DesignerContainer::setText(const QString& /*text*/){}
void DesignerContainer::setTheme(ITheme * /*theme*/, QFont * /*fnt*/){}
void DesignerContainer::find(const QString& /*find*/, bool /*forward*/){}
void DesignerContainer::replace(const QString& /*find*/, const QString& /*replace*/, bool /*findNext*/, bool /*forward*/){}
void DesignerContainer::replaceAll(const QString& /*find*/, const QString& /*replace*/){}
QString DesignerContainer::selectedText(){ return ""; }

void DesignerContainer::activate()
{
    _edit->activate();
    emit errorListChanged(NULL);
}



bool DesignerContainer::isModified()
{
    return _edit->isModified();
}

//------------------------------

void DesignerContainer::undo(){ _edit->undo(); }
void DesignerContainer::redo(){ _edit->redo(); }
void DesignerContainer::copy(){ _edit->copy(); }
void DesignerContainer::cut(){ _edit->cut(); }
void DesignerContainer::paste(){ _edit->paste(); }
void DesignerContainer::del(){ _edit->del(); }
void DesignerContainer::selectAll(){ _edit->selectAll(); }

void DesignerContainer::uppercase(){}
void DesignerContainer::lowercase(){}
void DesignerContainer::capitalize(){}
void DesignerContainer::jumpLine(int){}
void DesignerContainer::jumpOffset(int){}

bool DesignerContainer::reset()
{
    return false;
}



// -------------------------------

void DesignerContainer::focusInEvent(QFocusEvent *)
{
}

}
